extends Node2D


var isPaused = false
var at6

var background

# Called when the node enters the scene tree for the first time.
func _ready():
	self.visible = true
	$GameOver.visible = false
	$Exit.visible = true
#	$Floor6.visible = true
#	$Floor8.visible = false
	background = get_node("Background")
	var Floor6 = preload("res://Scns/Floors/Floor6.tscn").instance()
	add_child_below_node(background,Floor6)
	at6=true 
	GlobalVar.TrueDoor = randi()%GlobalVar.DoorCnt
	print(GlobalVar.TrueDoor)
	CommonSignals.connect("GameStop",self,"_on_ExitBtn_pressed")
	CommonSignals.connect("GamePause",self,"_on_PauseBtn_pressed")
	CommonSignals.connect("EnemyCaughtPlayer",self,"_on_EnemyCaughtPlayer")
	CommonSignals.connect("GameRestart",self,"_on_Restart")
	CommonSignals.connect("SwitchFloor",self,"_on_SwitchFloor")
	
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass

func _on_SwitchFloor():
	
	if at6==true:
#		$Floor6.visible = false
#		$Floor8.visible = true
		var Floor8 = preload("res://Scns/Floors/Floor8.tscn").instance()
		var floor6 = get_node("Floor6")
		add_child_below_node(background,Floor8)
		floor6.free()
		
		
		at6 = false
	else:
#		$Floor8.visible = false
#		$Floor6.visible = true
		var Floor6 = preload("res://Scns/Floors/Floor6.tscn").instance()
		var floor8 = get_node("Floor8")
		add_child_below_node(background,Floor6)
		floor8.free()
		
		at6 = true

func _on_ExitBtn_pressed():
	get_tree().quit()

func _on_PauseBtn_pressed():
	if isPaused == false:
		get_tree().paused = true
		isPaused = true
	else:
		get_tree().paused = false
		isPaused = false

func _on_EnemyCaughtPlayer():
	get_tree().paused = true
	$GameOver.visible = true
	$Exit.visible = false
	
func _on_Restart():
	get_tree().reload_current_scene()
	get_tree().paused = false
	

